﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace SmallERP.Host
{
    public class XmlOperator
    {
        private XmlDocument xmldoc = new XmlDocument();//定义XmlDocument对象
        private string xmlfile;//xml文件

        public void Open(string xmlfile)
        {
            xmldoc.Load(xmlfile);
            this.xmlfile = xmlfile;
        }

        public void Save()
        {
            xmldoc.Save(xmlfile);
        }

        public XmlNode GetSingleNode(string NodeName)
        {
            string xpath = "//" + NodeName;
            XmlNode singleNode = xmldoc.SelectSingleNode(xpath);
            return singleNode;
        }

        public void UpdateNodeInnerText(string NodeName, string InnerText)
        {
            XmlNode node = GetSingleNode(NodeName);
            if (node != null)
            {
                node.InnerText = InnerText;
            }
        }
    }
}
